package edu.pku.sei.gefcommon.descriptor.descriptors;

import org.eclipse.ui.views.properties.TextPropertyDescriptor;

import edu.pku.sei.gefcommon.common.resourceManager.Color;

public class ColorPropertyDescriptor extends TextPropertyDescriptor {

	public ColorPropertyDescriptor(Object id, String name,String catalog) {
		super(id, name);
		this.setCategory(catalog);
		this.setValidator(GeometryValidator.colorValidator);
	}
	static public String fromModel(Color value){
		if(value == null) return "";
		return value.red+","+value.green+","+value.blue;
	}
	static public Color toModel(String value){
		if(value==null||value=="") return Color.TRANSPARENT;
		String[] clr = value.split(",");
		Color c = new Color();
		c.red = Integer.parseInt(clr[0]);
		c.green = Integer.parseInt(clr[1]);
		c.blue = Integer.parseInt(clr[2]);
		return c;
	}
}
